package com.example.administrator.szb.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.example.administrator.szb.R;
import com.example.administrator.szb.adapter.BaseAdapter;
import com.example.administrator.szb.activity.base.BaseActivity;
import com.example.administrator.szb.bean.ProjectDetail;
import com.example.administrator.szb.tinkerutil.SampleApplicationLike;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by D N on 2017/10/28.
 */

public class FWJGActivity extends BaseActivity {
    @Bind(R.id.fwjg_recyclerview)
    RecyclerView fwjgRecyclerview;
    private List<ProjectDetail.ServiceCounBean> list;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fwjg_activity);
        ButterKnife.bind(this);
        SampleApplicationLike.getActivitiesInstance().add(this);
        initToolbar(R.id.fwjg_toolbar_include, "服务机构");
        String str = getIntent().getStringExtra("datas");
        if (TextUtils.isEmpty(str)){
            str="[]";
        }
        list = JSON.parseArray(str,ProjectDetail.ServiceCounBean.class);
        requestData();//获取服务机构数据
    }

    private void requestData() {
        initRecyclerview();
    }

    private void initRecyclerview() {
        BaseAdapter<ProjectDetail.ServiceCounBean> adapter = new BaseAdapter<ProjectDetail.ServiceCounBean>(this,list) {
            @Override
            public void convert(int position, BaseViewHolder holder,ProjectDetail.ServiceCounBean dataBean) {
                if (TextUtils.isEmpty(dataBean.getReason())){
                    ((LinearLayout)holder.getView(R.id.fwjg_ll_yy)).setVisibility(View.GONE);
                }else {
                    ((TextView)holder.getView(R.id.fwjg_text_yy)).setText(dataBean.getReason());
                }

                if (!TextUtils.isEmpty(dataBean.getZhenshi_img())){
                    Glide.with(FWJGActivity.this).load(dataBean.getZhenshi_img()).error(R.drawable.mrtx).into(((ImageView)holder.getView(R.id.imageView49)));
                }

                ((TextView)holder.getView(R.id.textView151)).setText(dataBean.getCompany()+"-"+dataBean.getName());
                ((TextView)holder.getView(R.id.textView152)).setText("机构地址：" + dataBean.getCity());


                //if ((double)ddxqBean.getData().getStatusType() != 9 || (double)ddxqBean.getData().getStatusType() != 4)

                ((TextView)holder.getView(R.id.textView154)).setText(dataBean.getStatus());

            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.view_fwjg_item;
            }
        };
        fwjgRecyclerview.setLayoutManager(new LinearLayoutManager(this));
        fwjgRecyclerview.setAdapter(adapter);
    }
}
